﻿using Activity.API;
using Ext.Net;
using System;
using System.Web.UI;

public partial class OderMaster : Page
{
    private WorkOrderHandler handler = new WorkOrderHandler();
    private string mid;
    private int tid_id = 0;
    private int customUserType = 0;
    private int userID = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        mid = Request.Params["mid"];
        int.TryParse(Request.Params["tidId"], out tid_id);
        if (Session["UserID"] != null)
        {
            int.TryParse(Session["UserID"].ToString(), out userID);
            this.UserID.Text = Session["UserID"].ToString();
        }
        if (Session["UserName"] != null)
        {
            this.UserName.Text = Session["UserName"].ToString();
        }
        if (Session["CustomUserType"] != null)
        {
            int.TryParse(Session["CustomUserType"].ToString(), out customUserType);
            this.CustomUserType.Text = customUserType.ToString();
        }
        var all = new DictionarylVO { Code = "", Name = "全部", Value = -1 };
        var wdTypeSource = handler.GetWdTypeList();
        wdTypeSource.Insert(0, all);
        this.cbParentCode.GetStore().DataSource = wdTypeSource;
        var w_type = handler.GetDicTionaryList("w_type");
        w_type.Insert(0, all);
        this.cbW_Type.GetStore().DataSource = w_type;
        if (!X.IsAjaxRequest)
        {
            this.cbParentCode.SetValueAndFireSelect("全部");
            this.cbW_Type.SetValueAndFireSelect("全部");
        }
    }

    protected void RefreshDataSet(object sender, StoreReadDataEventArgs e)
    {
        BtnQurey();
    }

    [DirectMethod(Namespace = "CompanyX")]
    public void BtnQurey()
    {
        var w_code = this.txtW_Code.Text;
        DateTime? startDate = null;
        if (this.txtTimeBegin.SelectedValue != null)
        {
            startDate = this.txtTimeBegin.SelectedDate;
        }
        DateTime? endDate = null;
        if (this.txtTimeEnd.SelectedValue != null)
        {
            endDate = this.txtTimeEnd.SelectedDate;
        }
        var parentCode = cbParentCode.SelectedItem.Value;
        int w_type = 0;
        int.TryParse(cbW_Type.SelectedItem.Value, out w_type);
        string userName = this.UserName.Text;
        //int pageSize = this.gpStore.PageSize;
        //int pageIndex = this.gp;
        this.gpList.GetStore().DataSource = handler.GetWordOrderVO(w_code, startDate, endDate, parentCode, w_type, tid_id, userID, customUserType);
        this.gpList.DataBind();
    }

    protected void btnQuery_DirectClick(object sender, DirectEventArgs e)
    {
        BtnQurey();
    }
}